package com.js.service.impl;

import com.js.entity.DAdmin;
import com.js.dao.DAdminDao;
import com.js.service.DAdminService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import java.util.List;
import javax.annotation.Resource;

/**
 * (DAdmin)表服务实现类
 *
 * @author makejava
 * @since 2022-06-15 14:03:42
 */
@Service("dAdminService")
public class DAdminServiceImpl implements DAdminService {
    @Resource
    private DAdminDao dAdminDao;

    /**
     * 通过ID查询单条数据
     *
     * @param aId 主键
     * @return 实例对象
     */
    @Override
    public DAdmin queryById(Integer aId) {
        return this.dAdminDao.queryById(aId);
    }

    /**
     * 分页查询
     *
     * @param dAdmin 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<DAdmin> queryByPage(DAdmin dAdmin, PageRequest pageRequest) {
        long total = this.dAdminDao.count(dAdmin);
        return new PageImpl<>(this.dAdminDao.queryAllByLimit(dAdmin, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param dAdmin 实例对象
     * @return 实例对象
     */
    @Override
    public DAdmin insert(DAdmin dAdmin) {
        this.dAdminDao.insert(dAdmin);
        return dAdmin;
    }

    /**
     * 修改数据
     *
     * @param dAdmin 实例对象
     * @return 实例对象
     */
    @Override
    public DAdmin update(DAdmin dAdmin) {
        this.dAdminDao.update(dAdmin);
        return this.queryById(dAdmin.getAId());
    }

    /**
     * 通过主键删除数据
     *
     * @param aId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer aId) {
        return this.dAdminDao.deleteById(aId) > 0;
    }
    /**
    * 查询所有
    * @return 列表
    */
    @Override
    public List<DAdmin> queryAll(){
        return this.dAdminDao.queryAll();
    }
}
